package model

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSplitDataBytes(t *testing.T) {
	commanCase := []byte{
		0x2a, 0x00, 0x00, 0x00, 0xa1, 0x89, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
		0x03, 0x77, 0x77, 0x77, 0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00,
		0x01, 0x00, 0x01, 0x00, 0x00, 0x29, 0x04, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x00,
		0x00, 0x00, 0x9f, 0x81, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x77,
		0x77, 0x77, 0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00,
	}
	result := splitDataBytes(commanCase)
	expected1 := []byte{
		0xa1, 0x89, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x77, 0x77, 0x77,
		0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00,
		0x00, 0x29, 0x04, 0xb0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
	assert.Equal(t, expected1, result[0])
	expected2 := []byte{
		0x9f, 0x81, 0x01, 0x20, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x77,
		0x77, 0x77, 0x05, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x1c, 0x00,
	}
	assert.Equal(t, expected2, result[1])

	realCase := []byte{
		31, 0, 0, 0, 99, 179, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
		3, 119, 119, 119, 5, 98, 97, 105, 100, 117, 3, 99, 111, 109, 0, 0,
		1, 0, 1, 31, 0, 0, 0, 97, 196, 1, 0, 0, 1, 0, 0, 0,
		0, 0, 0, 3, 119, 119, 119, 5, 98, 97, 105, 100, 117, 3, 99, 111,
		109, 0, 0, 28, 0, 1,
	}
	result = splitDataBytes(realCase)
	expected3 := []byte{
		99, 179, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0,
		3, 119, 119, 119, 5, 98, 97, 105, 100, 117, 3, 99, 111, 109, 0, 0,
		1, 0, 1,
	}
	assert.Equal(t, expected3, result[0])
	expected4 := []byte{
		97, 196, 1, 0, 0, 1, 0, 0, 0,
		0, 0, 0, 3, 119, 119, 119, 5, 98, 97, 105, 100, 117, 3, 99, 111,
		109, 0, 0, 28, 0, 1,
	}
	assert.Equal(t, expected4, result[1])
}
